package com.binest.draftBox.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.binest.draftBox.domain.DraftBox;
import com.binest.draftBox.service.IDraftBoxService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.binest.common.annotation.Log;
import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.enums.BusinessType;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.common.core.page.TableDataInfo;

/**
 * 草稿箱Controller
 * 
 * @author wwd
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/draftBox")
public class DraftBoxController extends BaseController
{
    @Autowired
    private IDraftBoxService draftBoxService;

    /**
     * 查询草稿箱列表
     */
//    @PreAuthorize("@ss.hasPermi('draftBox:draftBox:list')")
    @GetMapping("/list")
    public TableDataInfo list(DraftBox draftBox)
    {
        startPage();
        List<DraftBox> list = draftBoxService.selectDraftBoxList(draftBox);
        return getDataTable(list);
    }

    /**
     * 导出草稿箱列表
     */
    @PreAuthorize("@ss.hasPermi('draftBox:draftBox:export')")
    @Log(title = "草稿箱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DraftBox draftBox)
    {
        List<DraftBox> list = draftBoxService.selectDraftBoxList(draftBox);
        ExcelUtil<DraftBox> util = new ExcelUtil<DraftBox>(DraftBox.class);
        util.exportExcel(response, list, "草稿箱数据");
    }

    /**
     * 获取草稿箱详细信息
     */
    @PreAuthorize("@ss.hasPermi('draftBox:draftBox:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(draftBoxService.selectDraftBoxById(id));
    }

    /**
     * 新增草稿箱
     */
    @PreAuthorize("@ss.hasPermi('draftBox:draftBox:add')")
    @Log(title = "草稿箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DraftBox draftBox)
    {
        return toAjax(draftBoxService.insertDraftBox(draftBox));
    }

    /**
     * 修改草稿箱
     */
    @PreAuthorize("@ss.hasPermi('draftBox:draftBox:edit')")
    @Log(title = "草稿箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DraftBox draftBox)
    {
        return toAjax(draftBoxService.updateDraftBox(draftBox));
    }

    /**
     * 删除草稿箱
     */
    @PreAuthorize("@ss.hasPermi('draftBox:draftBox:remove')")
    @Log(title = "草稿箱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(draftBoxService.deleteDraftBoxByIds(ids));
    }
}
